﻿
using Enferno.Web.StormUtils;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Enferno.Public.Web.Test
{
    [TestClass]
    public class PriceCalulatorTests
    {       
        [TestMethod]
        [Description("Calculate price with Vat")]
        public void PriceTest01()
        {
            var stubStormContext = new Enferno.Web.StormUtils.Fakes.StubIStormContext()
            {
                ShowPricesIncVatGet = () => new bool?(true),
                ConfigurationGet = () => new StormConfigurationSection()
            };
            StormContext.SetInstance(stubStormContext);

            const decimal price = 100M;
            const decimal vatRate = 1.25M;
            

            var result = PriceCalulator.Price(price, vatRate);

            Assert.AreEqual(125M, result);

        }

        [TestMethod]
        [Description("Calculate price excluding Vat")]
        public void PriceTest02()
        {
            var stubStormContext = new Enferno.Web.StormUtils.Fakes.StubIStormContext()
            {
                ShowPricesIncVatGet = () => new bool?(false),
                ConfigurationGet = () => new StormConfigurationSection()
            };
            StormContext.SetInstance(stubStormContext);

            const decimal price = 100M;
            const decimal vatRate = 1.25M;

            var result = PriceCalulator.Price(price, vatRate);

            Assert.AreEqual(100M, result);

        }

        [TestMethod]
        [Description("Calculate null price returns zero")]
        public void PriceTest03()
        {

            decimal? price = null;
            const decimal vatRate = 1.25M;

            var result = PriceCalulator.Price(price, vatRate);

            Assert.AreEqual(0, result);

        }

        [TestMethod]
        [Description("Calculate zero price")]
        public void PriceTest04()
        {
            var stubStormContext = new Enferno.Web.StormUtils.Fakes.StubIStormContext()
            {
                ShowPricesIncVatGet = () => new bool?(true),
                ConfigurationGet = () => new StormConfigurationSection()
            };
            StormContext.SetInstance(stubStormContext);

            decimal? price = 0M;
            const decimal vatRate = 1.25M;

            var result = PriceCalulator.Price(price, vatRate);

            Assert.AreEqual(0, result);
        }

        [TestMethod]
        [Description("Calculate negitve price should return zero")]
        public void PriceTest05()
        {
            //Arrange
            var stubStormContext = new Enferno.Web.StormUtils.Fakes.StubIStormContext()
            {
                ShowPricesIncVatGet = () => new bool?(true),
                ConfigurationGet = () => new StormConfigurationSection()
            };
            StormContext.SetInstance(stubStormContext);


            decimal? price = -100M;
            const decimal vatRate = 1.25M;

            //Act
            var result = PriceCalulator.Price(price, vatRate);

            //Assert
            Assert.AreEqual(-125M, result);

        }
    }
}
